<?php

namespace teach\service;

use Yii;
use teach\components\WeChat;

class Streaming
{

    public function deliverGoods($message)
    {
        //$redis = Yii::$app->redis;
        $SendWeChatMessage = new SendWechatMessage();
        //告诉用户已经发货

        $WeChat = new WeChat();
        //小程序模板消息
//        while (true) {
//            $formid = $redis->rpop("formid_{$message["openid"]}");
//            $status = $WeChat->sendMsg($SendWeChatMessage->deliver($message["openid"], $formid, $message["out_trade_no"], $message["phone"], $message["name"], $message["logistics"], $message["order_num"], $message["tip"]));
//            if ($status['errcode'] == 0 || $formid == false) {
//                break;
//            }
//        }
        //小程序订阅消息
        $WeChat->send($SendWeChatMessage->delivers($message["openid"], $message["out_trade_no"], $message["logistics"], $message["order_num"]));


        //查找商家,发送小程序消息
        $shop = new Business();
        $andWhere = " id = {$message["mid"]} ";
        $store = $shop->storeOne($andWhere);
//        while (true) {
//            $formid_store = $redis->rpop("formid_{$store['openid']}");
//            $status_store = $WeChat->sendMsg($SendWeChatMessage->deliver($store['openid'], $formid_store, $message['out_trade_no'], $message['phone'], $message['name'], $message["logistics"], $message["order_num"], $message["tip"]));
//            if ($status_store['errcode'] == 0 || $formid_store == false) {
//                break;
//            }
//        }
        //小程序订阅消息
        $WeChat->send($SendWeChatMessage->delivers($store["openid"], $message["out_trade_no"], $message["logistics"], $message["order_num"]));


        return true;
    }
}